//
//  LKUserInfoModel.swift
//  新浪微博
//
//  Created by 胡不归是大虾 on 16/9/25.
//  Copyright © 2016年 胡不归是大虾. All rights reserved.
//

import UIKit

class LKUserInfoModel: NSObject ,NSCoding{
    var access_token: String?
    var uid: String?
    var expires_in : Int =  0 {
        didSet{
            //过期时间 = 当前时间+expires_in
            expires_date = Date(timeIntervalSinceNow: Double(expires_in))
        }
    }
    //用户名
    var name: String?
    
    //用户头像 180 * 180
    var avatar_large: String?
    var expires_date:Date?
    
    //重写构造方法,字典转模型
    init( dict: [ String : Any ] ) {
        super.init()
        setValuesForKeys(dict)
    }
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
    }
    //归档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(expires_date, forKey: "expires_in")
        aCoder.encode(name, forKey: "name")
        aCoder.encode(avatar_large, forKey: "avatar_large")
    }
    //解档
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        uid = aDecoder.decodeObject(forKey: "uid") as? String
        expires_date = aDecoder.decodeObject(forKey: "expires_in") as? Date
        name = aDecoder.decodeObject(forKey: "name") as? String
        avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as? String
    }
}
